package com.example.chapter3.homework.PageFragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.chapter3.homework.R;
import com.example.chapter3.homework.List.*;

import java.util.ArrayList;
import java.util.List;

public class mPageFrament4List extends Fragment {

    private List<CodeLanguage> codeLanList=new ArrayList<CodeLanguage>();

    private String [] name={"Java","C","Python","C++","C#",
            "JavaScript","PHP","SQL","Ruby","Swift","MATLAB",
            "Groovy","Go","Perl"};

    private double [] rate={15.058,14.211,9.260,6.705,4.365,
            2.304,2.167,1.977,1.636,1.121,1.078,1.070,1.016,
            0.918};

    private int [] imageId={R.drawable.lan_java,R.drawable.lan_c,R.drawable.lan_py,
            R.drawable.lan_cpp,R.drawable.lan_csharp,R.drawable.lan_js,
            R.drawable.lan_php,R.drawable.lan_sql,R.drawable.lan_ruby,
            R.drawable.lan_swift,R.drawable.lan_matlab,R.drawable.lan_groovy,
            R.drawable.lan_go,R.drawable.lan_perl};

    private View view;

    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
        view= inflater.inflate(R.layout.fragment4_list_for_viewpager, container, false);

        // 初始化数据集
        initData();
        RecyclerView recyclerView= view.findViewById(R.id.rl_test);

        // 设置依赖布局
        LinearLayoutManager layoutManager=new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);

        // 设置数据绑定
        CodeLanAdapter mAdapter=new CodeLanAdapter(codeLanList);
        recyclerView.setAdapter(mAdapter);

        return view;
    }

    private void initData(){
        for(int i=0;i<14;i++){
            CodeLanguage reitem=new CodeLanguage(i+1,name[i],rate[i],imageId[i]);
            codeLanList.add(reitem);
        }
    }
}
